package com.example.fw;

import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.Select;

import com.example.tests.ContactData;
import com.example.tests.TestBase;

public class ContactHelper extends HelperBase {

	protected ContactHelper(ApplicationManager manager) {
		super(manager);
		
	}

	public void submitAddressbookEntry() {
		manager.driver.findElement(By.name("submit")).click();
	}
	
	public void gotoAddAddressbookPage() {
		manager.driver.findElement(By.linkText("add new")).click();
	}

	public void fillAddAddressbookEntryForm(ApplicationManager applicationManager, TestBase testBase, ContactData addrData) {
		manager.driver.findElement(By.name("firstname")).clear();
		manager.driver.findElement(By.name("firstname")).sendKeys(addrData.firstName);
		manager.driver.findElement(By.name("lastname")).clear();
		manager.driver.findElement(By.name("lastname")).sendKeys(addrData.lastName);
		manager.driver.findElement(By.name("address")).clear();
		manager.driver.findElement(By.name("address")).sendKeys(addrData.addr);
		manager.driver.findElement(By.name("home")).clear();
		manager.driver.findElement(By.name("home")).sendKeys(addrData.homePhone);
		manager.driver.findElement(By.name("mobile")).clear();
		manager.driver.findElement(By.name("mobile")).sendKeys(addrData.mobilePhone);
		manager.driver.findElement(By.name("work")).clear();
		manager.driver.findElement(By.name("work")).sendKeys(addrData.workPhone);
		manager.driver.findElement(By.name("email")).clear();
		manager.driver.findElement(By.name("email")).sendKeys(addrData.email);
		manager.driver.findElement(By.name("email2")).clear();
		manager.driver.findElement(By.name("email2")).sendKeys(addrData.email2);
		new Select(manager.driver.findElement(By.name("bday"))).selectByVisibleText(addrData.bdayDay);
		new Select(manager.driver.findElement(By.name("bmonth"))).selectByVisibleText(addrData.bdayMonth);
		manager.driver.findElement(By.name("byear")).clear();
		manager.driver.findElement(By.name("byear")).sendKeys(addrData.bdayYear);
		manager.driver.findElement(By.name("address2")).clear();
		manager.driver.findElement(By.name("address2")).sendKeys(addrData.addr2);
		manager.driver.findElement(By.name("phone2")).clear();
		manager.driver.findElement(By.name("phone2")).sendKeys(addrData.phone2);
	}

}
